package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className CheckItemServiceImpl
 */
@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    //添加检查项
    public void addCheckItem(CheckItem checkItem) {
        checkItemMapper.insertCheckItem(checkItem);
    }

    //删除检查项
    public void deleteCheckItem(Integer id) {
        checkItemMapper.deleteCheckItemById(id);
    }

    //分页查询检查项
    public PageResult getCheckItemByPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<CheckItem> checkItemList = checkItemMapper.selectCheckItemByPage(queryPageBean.getQueryString());
        return new PageResult(new PageInfo(checkItemList));
    }

    //修改检查项
    public void editCheckItem(CheckItem checkItem) {
        checkItemMapper.updateCheckItem(checkItem);
    }

    //根据id查询检查项
    public CheckItem findById(Integer id) {
        return checkItemMapper.selectCheckItemById(id);
    }

    //查询所有检查项
    public List<CheckItem> getAllCheckItem() {
        return checkItemMapper.selectAllCheckItem();
    }

    //根据检查组id查询检查项id
    public List<Integer> findCheckItemIdsByCheckGroupId(Integer groupId) {
        return checkItemMapper.selectCheckItemIdsByGroupId(groupId);
    }
}
